package com.rpay.service.admin.impl;

import com.rpay.dao.mapper.RpayAdminUserRoleMapper;
import com.rpay.model.admin.RpayAdminUser;
import com.rpay.model.admin.RpayAdminUserRole;
import com.rpay.service.admin.ISystemUserRoleService;
import com.rpay.service.base.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 */
@Service(value = "userRoleServiceImpl")
public class SecUserRoleServiceImpl extends BaseServiceImpl<RpayAdminUserRole> implements ISystemUserRoleService {

    @Autowired
    private RpayAdminUserRoleMapper systemUserRoleMapper;

    @Override
    public List<RpayAdminUserRole> getRoleByUser(RpayAdminUser user) {
        //不建议使用Example的方式来操作，后续维护很麻烦
        return systemUserRoleMapper.getRoleByUser(user);
    }

    public List<Map> getRoleandNameByUser(RpayAdminUser user) {
        //不建议使用Example的方式来操作，后续维护很麻烦
        return systemUserRoleMapper.getRoleandNameByUser(user);
//        return super.getSqlSessionTemplate().selectList("getRoleandNameByUser", user);
    }

    @Override
    public boolean checkIsSuperAdmin(String user_name) {
        boolean isSuperadmin = false;
//        Integer cn = super.getSqlSessionTemplate().selectOne("checkIsSuperadmin", user_name);
        Integer cn = systemUserRoleMapper.checkIsSuperadmin(user_name);
        if (cn > 0) {
            isSuperadmin = true;
        }
        return isSuperadmin;
    }

}
